package com.weixing.mall.provider.controller.ads;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.ads.MediaAgentBindDto;
import com.weixing.mall.provider.model.query.MediaAgentBindQuery;
import com.weixing.mall.provider.service.IMediaAgentBindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wx
 * @Date 2019/9/9 17:34
 * @Version 1.0
 */
@RestController
@RequestMapping("MediaAgentBind")
@Api(value = "专属广告专员Api" ,tags = "专属广告专员")
public class MediaAgentBindController extends BaseController {
    @Autowired
    private IMediaAgentBindService mediaAgentBindService;

    @ApiOperation("查询")
    @GetMapping("")
    public Result selectOfPage(MediaAgentBindQuery mediaAgentBindQuery){
        return ResultUtil.success(mediaAgentBindService.selectOfPage(mediaAgentBindQuery,initMpPage()));
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(MediaAgentBindDto mediaAgentBindDto){
        mediaAgentBindService.save(mediaAgentBindDto);
        return ResultUtil.success();
    }

    @ApiOperation("删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "专属广告员id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable Long id){
        return mediaAgentBindService.removeById(id) ? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation("查看")
    @GetMapping("selectDetails/{id}")
    public Result selectDetails(@PathVariable Long id){
        return ResultUtil.success(mediaAgentBindService.getById(id));
    }

    @ApiOperation(value = "根据广告专员查询绑定代理商")
    @GetMapping(value = "getBindAgent/{id}")
    public Result getBindAgentList(@PathVariable(value = "id")Long id){//广告专员ID
        MediaAgentBindQuery mabq = new MediaAgentBindQuery();
        mabq.setDirectorId(id);
        return  ResultUtil.success( mediaAgentBindService.selectOfPage(mabq));
    }
}
